package com.ll.gulimall.cart.vo;

import lombok.Data;

import javax.swing.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 整个购物车
 */

public class Cart {

    List<CartItem> items = new ArrayList<>();
    private Integer count;//商品的数量
    private Integer countType;//商品的类型有几种
    private BigDecimal totalAmount;//商品总价
    private BigDecimal reduce = new BigDecimal("0.00");//见面价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCount() {
        int count = 0;
        if (items.size() > 0) {
            for (CartItem item : items) {
                count = count + item.getCount();
            }
        }
        return count;
    }


    public Integer getCountType() {
        int count = 0;
        if (items.size() > 0) {
            for (CartItem item : items) {
                count += 1;
            }
        }
        return count;
    }


    public BigDecimal getTotalAmount() {
        //1.计算购物项总价
        BigDecimal amount = new BigDecimal("0.00");
        if (items.size() > 0) {
            for (CartItem item : items) {
                if(item.getCheck()){
                    amount = amount.add(item.getTotalPrice());
                }

            }
        }

        //2.减去优惠总价
        return amount.subtract(reduce);
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
